package com.leyou.trade.web;

import com.leyou.trade.dto.PayResultDTO;
import com.leyou.trade.service.OrderService;
import com.leyou.trade.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private PayService payService;
    /**
     * 根据订单编号创建支付链接
     * @param orderId 订单编号
     * @return 支付链接
     */
   @GetMapping("/url/{id}")
   public ResponseEntity<String> createPayUrl(@PathVariable("id") Long orderId) {
       return ResponseEntity.ok(payService.createPayUrl(orderId));
   }

    /**
     * 处理微信支付的回调
     * @param notifyParam
     * @return
     */
    @PostMapping(value = "/wx/notify",produces = "application/xml")
    public ResponseEntity<PayResultDTO> handlerNotify(@RequestBody Map<String,String> notifyParam){

        this.payService.handlerNotify(notifyParam);
        HashMap<String,String> resultMap = new HashMap<>();
        resultMap.put("return_code","success");
        resultMap.put("return_msg","ok");

        return ResponseEntity.ok(new PayResultDTO());
    }

}
